﻿/*
 ***************************************************************************
 * Microsoft Visual C# .NET
 * 名称：       App_Input_PersonTrainForm
 * 类型：       控制层
 * 功能说明：   培训申请编辑页面
 * 作者：       徐傲明
 * 创建日期：   2008/3/13
 * 修改日期     修改者      修改内容
 * 
 * 
 * ---
 ***************************************************************************
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.App.Input.Dao;
using Shpm.App.Input.Bean;
using Shpm.App.Commons.Db.Beans.Master;
using Shpm.System;
using log4net;
using Shpm.App.Commons.Utils;
using Shpm.System.Validator;
using Shpm.System.Web.Control;
using Shpm.App.Master.Dao;
using Shpm.App.Master.Bean;

public partial class App_Input_PersonTrainUpdForm : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //setPageControls();
        if (!Page.IsPostBack)
        {

            

            //接收页面传递参数
            if (Context.Items["PERSON_ID"] != null)
            {
                ViewState["PERSON_ID"] = Context.Items["PERSON_ID"];

            }
            else
            {
                ViewState["PERSON_ID"] = null;
            }
            if (Context.Items.Contains("URL"))
            {
                ViewState["URL"] = Convert.ToString(Context.Items["URL"]);
            }
            if (Context.Items.Contains("MAIN_URL"))
            {
                ViewState["MAIN_URL"] = Convert.ToString(Context.Items["MAIN_URL"]);
            }
            if (Context.Items.Contains("CMB_GROUP_ID"))
            {
                this.ViewState["CMB_GROUP_ID"] = Context.Items["CMB_GROUP_ID"];
            }
            if (Context.Items.Contains("CMB_JOB_ID"))
            {
                this.ViewState["CMB_JOB_ID"] = Context.Items["CMB_JOB_ID"];
            }
            if (Context.Items.Contains("CMB_STATUS_ID"))
            {
                this.ViewState["CMB_STATUS_ID"] = Context.Items["CMB_STATUS_ID"];
            }
            if (Context.Items.Contains("EMPLOYEE_STATUS"))
            {
                this.ViewState["EMPLOYEE_STATUS"] = Context.Items["EMPLOYEE_STATUS"];
            }
            if (Context.Items.Contains("CMB_EMPLOYEE_ID"))
            {
                this.ViewState["CMB_EMPLOYEE_ID"] = Context.Items["CMB_EMPLOYEE_ID"];
            }
            if (Context.Items.Contains("CMB_EMPLOYEE_NAME"))
            {
                this.ViewState["CMB_EMPLOYEE_NAME"] = Context.Items["CMB_EMPLOYEE_NAME"];
            }
            if (this.Context.Items.Contains("ROW_ID") && !string.IsNullOrEmpty(Convert.ToString(Context.Items["ROW_ID"])))
            {
                this.ViewState["ROW_ID"] = Convert.ToString(this.Context.Items["ROW_ID"]);
            }
            else
            {
                this.ViewState["ROW_ID"] = null;
            }

            if (this.Context.Items.Contains("EMPLOYEE_ID") && !string.IsNullOrEmpty(Convert.ToString(Context.Items["EMPLOYEE_ID"])))
            {
                this.ViewState["EMPLOYEE_ID"] = Convert.ToString(this.Context.Items["EMPLOYEE_ID"]);
                string ss = Convert.ToString(this.ViewState["EMPLOYEE_ID"]);
            }
            else
            {
                this.ViewState["EMPLOYEE_ID"] = null;
            }

            if (this.Context.Items.Contains("ParamPageIndex"))
            {
                this.ViewState["ParamPageIndex"] = Convert.ToString(this.Context.Items["ParamPageIndex"]);
            }
            //加载控键数据
            setPageControls();
        }
    }



    void Page_PreRender(object sender, EventArgs e)
    {
        PersonTrainBean bean = new PersonTrainBean();
        PersonTrainDao dao = new PersonTrainDao();

        SysUserManager manager = new SysUserManager(Context);
        string userId = manager.getSysUserBean().getMstSysUserBean().SysUserId;

        //编辑时
        if (!string.IsNullOrEmpty(Convert.ToString(this.ViewState["ROW_ID"])))
        {
            loadDate();
        }
        //新建时
        else
        {
            bean.EmployeeId = Convert.ToString(this.ViewState["EMPLOYEE_ID"]);
            bean = dao.GetEmployeeName(bean);
            labelName.Text = bean.EmployeeName;
            rdoCancel.Enabled = false;
            rdoOk.Enabled = false;
            txtLeadText.ReadOnly = true;
            txtCommitText.ReadOnly = true;
             txtAuditingText.ReadOnly = true;
            btnAmount.Enabled = false;
            unCommit.Visible = true;
            auditingList.Visible = false;
            commitList.Visible = false;
            unAuditing.Visible = true;
            unAuditing.Text = "---";
            unCommit.Visible = true;
            unCommit.Text = "---";
            this.feedBack.Enabled = false;
        }

    }




    /*名称： loadDate
    *功能： 数据加载
    *参数： 无
    *返回： 无
    *说明： 无
    */
    public void loadDate()
    {

        PersonTrainBean bean = new PersonTrainBean();
        PersonTrainDao dao = new PersonTrainDao();
        SysUserManager manager = new SysUserManager(Context);
        string userId = manager.getSysUserBean().getMstSysUserBean().SysUserId;
        bean.RowId = Convert.ToInt32(this.ViewState["ROW_ID"]);
        bean = dao.GetPersonTrain(bean);

        //项目名称控键，申请日期控键，开始日期控键，结束日期控键，培训说明控键，预算控键，提交人控键的显示状态
        if (Convert.ToString(bean.EmployeeId) == userId && bean.EducateFlg == 0)
        {
            txtTrainName.ReadOnly = false;
            txtTime.ReadOnly = false;
            txtBeginDate.ReadOnly = false;
            txtEndDate.ReadOnly = false;
            txtAmount.ReadOnly = false;
            txtTrainText.ReadOnly = false;
            leadList.Enabled = true;
            btnSave.Enabled = true;
        }
        else
        {
            txtTrainName.ReadOnly = true;
            txtTime.ReadOnly = true;
            txtBeginDate.ReadOnly = true;
            txtEndDate.ReadOnly = true;
            txtAmount.ReadOnly = true;
            txtTrainText.ReadOnly = true;
            leadList.Enabled = false;
            btnSave.Enabled = false;
        }
        if (Convert.ToString(bean.LeadId) == userId && bean.CommitFlg == 0 && bean.EducateFlg == 1 && bean.LeadFlg==0)
        {
            commitList.Enabled = true;
            txtLeadText.ReadOnly = false;
        }
        else
        {
            commitList.Enabled = false;
            txtLeadText.ReadOnly = true;
        }

        //审批人控键，提交人意见控键的显示状态
        if (Convert.ToString(bean.CommitEmployeeId) == userId && bean.CommitFlg == 0 && bean.EducateFlg == 1 && bean.LeadFlg == 1)
        {
            auditingList.Enabled = true;
            txtCommitText.ReadOnly = false;
        }
        else
        {
            auditingList.Enabled = false;
            txtCommitText.ReadOnly = true;
        }

        //审批人意见控键的显示状态
        if (Convert.ToString(bean.AuditingEmployeeId) == userId && bean.LeadFlg == 1 && bean.CommitFlg == 1 && bean.EducateFlg == 1 && bean.AuditingFlg == 0 && bean.CancelFlg == 0)
        {
            txtAuditingText.ReadOnly = false;
            rdoOk.Enabled = true;
            rdoCancel.Enabled = true;
            rdoOk.Checked = true;
            btnAmount.Enabled = true;
        }
        else
        {
            txtAuditingText.ReadOnly = true;
            rdoOk.Enabled = false;
            rdoCancel.Enabled = false;
            btnAmount.Enabled = false;
        }

        //提交按钮的显示状态
        if ((Convert.ToString(bean.EmployeeId) == userId && bean.EducateFlg == 0) || (Convert.ToString(bean.CommitEmployeeId) == userId && bean.CommitFlg == 0 && bean.EducateFlg == 1 && bean.LeadFlg==1) || (Convert.ToString(bean.LeadId) == userId && bean.EducateFlg==1 && bean.LeadFlg==0))
        {
            btnSubmit.Enabled = true;
        }
        else
        {
            btnSubmit.Enabled = false;
        }

        //反馈按钮
        if("1".Equals(Convert.ToString(bean.FeedBackFlg)) || "1".Equals(Convert.ToString(bean.AuditingFlg)))
        {
            this.feedBack.Enabled = true;
        }
        else
            this.feedBack.Enabled = false;

        //置页面数据
        labelName.Text = bean.EmployeeName;
        memberNo.Value = bean.EmployeeId;
        rowId.Value = Convert.ToString(ViewState["ROW_ID"]);
        txtTrainName.Text = bean.EducateName;
        txtTime.Text = DateUtils.convertToString((DateTime)bean.EducateDate);
        txtBeginDate.Text = DateUtils.convertToString((DateTime)bean.BeginDate);
        txtEndDate.Text  = DateUtils.convertToString((DateTime)bean.EndDate);
        txtAmount.Text = string.Format("{0:N}", bean.EducateAmount);
        leadList.SelectedValue = bean.LeadId;
        if ((bean.EducateFlg == 0) || (bean.EducateFlg == 1 && bean.LeadFlg == 0 && (Convert.ToString(bean.LeadId) != userId)))
        {
            unCommit.Visible = true;
            commitList.Visible = false;
            unCommit.Text = "---";
        }
        else
        {
            unCommit.Visible = false;
            commitList.Visible = true;
            commitList.SelectedValue = bean.CommitEmployeeId;
        }

        //commitList.SelectedValue = bean.CommitEmployeeId;
        if ((bean.EducateFlg == 0) || (bean.EducateFlg == 1 && bean.LeadFlg == 0) || (bean.EducateFlg == 1 && bean.LeadFlg == 1 && bean.CommitFlg == 0 && (Convert.ToString(bean.CommitEmployeeId) != userId)))
        {
            unAuditing.Visible = true;
            auditingList.Visible = false;
            unAuditing.Text = "---";
        }
        else
        {
            unAuditing.Visible = false;
            auditingList.Visible = true;
            auditingList.SelectedValue = bean.AuditingEmployeeId;
        }

        txtTrainText.Text = bean.EducateMemo;
        txtLeadText.Text = bean.LeadMemo;
        txtCommitText.Text = bean.CommitMemo;
        txtAuditingText.Text = bean.AuditingMemo;
        if (bean.AuditingFlg == 1)
        {
            rdoOk.Checked = true;

        }
        else if (bean.CancelFlg == 1)
        {
            rdoCancel.Checked = true;
        }
    }





    /*名称： setPageControls
     *功能： 加载数据字典
     *参数： user
     *返回： 无
     *说明： 无
     */
    private void setPageControls()
    {

        IList list = new ArrayList();
        IList userList = new ArrayList();
        //审核人列表
        SysUserManager manager = new SysUserManager(Context);
        SysUserBean sysUserBean = manager.getSysUserBean();
        MstSysUserBean mstSysUserBean =
            sysUserBean == null ? null : sysUserBean.getMstSysUserBean();
        MstEmployeeBean mstEmpBean =
            sysUserBean == null ? null : sysUserBean.getEmployeeBean();
        PersonTrainBean bean = new PersonTrainBean();
        PersonTrainBean dataBean = new PersonTrainBean();
        PersonTrainDao dao = new PersonTrainDao();
        string loginId = mstSysUserBean == null ? "" : mstSysUserBean.SysUserId;
        string emplyId = mstSysUserBean == null ? "" : mstSysUserBean.EmployeeId;
        string departId=null;
        //编辑时
        if (!string.IsNullOrEmpty(Convert.ToString(this.ViewState["ROW_ID"])))
        {
            
            bean.RowId = Convert.ToInt32(this.ViewState["ROW_ID"]);
            bean = dao.GetPersonTrain(bean);
            dataBean.EmployeeId = bean.EmployeeId;
            bean = dao.GetDepartId(dataBean);
            departId = bean.DepartId;
        }
        else
        {
            //SysUserManager manager = new SysUserManager(Context);
            string userId = manager.getSysUserBean().getMstSysUserBean().SysUserId;
            dataBean.EmployeeId = userId;
            bean = dao.GetDepartId(dataBean);
            departId = bean.DepartId;
        }




        //检索部门编号
        PersonEmployeeBean employbean = new PersonEmployeeBean();
        EmployApplyDao employApplyDao = new EmployApplyDao();
        EmployeeDao employeeDao = new EmployeeDao();
        EmployeeBean employeeBean = new EmployeeBean();
        employeeBean.DepartId = departId;
        userList = employeeDao.FindDepartmentEmp(employeeBean);
        leadList.DataSource = userList;
        leadList.DataBind();


        employeeBean.DepartId = "2";
        
        //检索提交对象
        list = employeeDao.FindDepartmentEmp(employeeBean);
        commitList.DataSource = list;
        commitList.DataBind();

        IList authorityList = new ArrayList();
        IEnumerator enm = list.GetEnumerator();
        while (enm.MoveNext())
        {
            EmployeeBean enmBean = (EmployeeBean)enm.Current;
            employbean.EmployeeId = enmBean.EmployeeId;
            employbean = employApplyDao.CheckAuthority(employbean);
            if (Convert.ToInt32(employbean.JobLimit) >= 3)
            {
                authorityList.Add(enmBean);
            }

        }
        auditingList.DataSource=authorityList;
        auditingList.DataBind();
    }

    /*名称： btnSave_Click
     *功能： 保存培训申请
     *参数： 
     *返回： 无
     *说明： 无
     */
    protected void btnSave_Click(object sender, EventArgs e)
    {
        SysUserManager manager = new SysUserManager(Context);
        string userId = manager.getSysUserBean().getMstSysUserBean().SysUserId;
        PersonTrainBean bean = new PersonTrainBean();
        PersonTrainDao dao = new PersonTrainDao();
        ComValidateChecker validator = new ComValidateChecker();

        //数据验证
        validator.Add(new CheckRequired(txtTrainName.Text, new ComMessage("E0082", new string[] { "培训项目" })));
        validator.Add(new CheckRequired(txtTime.Text, new ComMessage("E0082", new string[] { "申请日期" })));
        validator.Add(new CheckDate(txtTime.Text, new ComMessage("E0037", "申请日期")));
        validator.Add(new CheckRequired(txtBeginDate.Text, new ComMessage("E0082", new string[] { "开始日期" })));
        validator.Add(new CheckDate(txtBeginDate.Text, new ComMessage("E0037", "开始日期")));
        validator.Add(new CheckDateRange(DateUtils.convertToString(DateTime.Now.Date), txtTime.Text, new ComMessage("E0330", new string[] { "申请日期", "当前日期" })));
        validator.Add(new CheckDateRange(txtTime.Text, txtBeginDate.Text, new ComMessage("E0330", new string[] { "开始日期", "申请日期" })));
        validator.Add(new CheckRequired(txtEndDate.Text, new ComMessage("E0082", new string[] { "结束日期" })));
        validator.Add(new CheckDate(txtEndDate.Text, new ComMessage("E0037", "结束日期")));
        validator.Add(new CheckDateRange(txtBeginDate.Text, txtEndDate.Text, new ComMessage("E0330", new string[] { "结束日期", "开始日期" })));
        validator.Add(new CheckDouble(txtAmount.Text, 9, 2, new ComMessage("E0036", new string[] { "培训预算" })));

        //校验不通过
        if (!validator.DoValidator())
        {
            ((Design_MasterPage)this.Master).InfoMessage = validator.ErrorMessage;
            return;
        }


        //编辑时候
        if (!string.IsNullOrEmpty(Convert.ToString(this.ViewState["ROW_ID"])))
        {
            bean.RowId = Convert.ToInt32(this.ViewState["ROW_ID"]);
            bean.EducateName = txtTrainName.Text;
            bean.EmployeeId = Convert.ToString(this.ViewState["EMPLOYEE_ID"]);
            bean.EducateDate = Convert.ToDateTime(txtTime.Text);
            bean.BeginDate = Convert.ToDateTime(txtBeginDate.Text);
            bean.EndDate = Convert.ToDateTime(txtEndDate.Text);
            if (!string.IsNullOrEmpty(txtAmount.Text))
            {
                bean.EducateAmount = Convert.ToDecimal(txtAmount.Text);
            }
            else
            {
                bean.EducateAmount = 0;
            }
            bean.LeadId=leadList.SelectedValue;
            bean.EducateMemo = txtTrainText.Text;
            bean.EducateFlg = 0;
            bean.LeadFlg = 0;
            bean.CommitFlg = 0;
            bean.AuditingFlg = 0;
            bean.CancelFlg = 0;           
            bean.UserId = userId;
            dao.UpdPersonTrain(bean);
        }
        //新建时候
        else
        {
            bean.EducateName = txtTrainName.Text;
            bean.EmployeeId = Convert.ToString(this.ViewState["EMPLOYEE_ID"]);
            bean.EducateDate = Convert.ToDateTime(txtTime.Text);
            bean.BeginDate = Convert.ToDateTime(txtBeginDate.Text);
            bean.EndDate = Convert.ToDateTime(txtEndDate.Text);
            if (!string.IsNullOrEmpty(txtAmount.Text))
            {
                bean.EducateAmount = Convert.ToDecimal(txtAmount.Text);
            }
            else
            {
                bean.EducateAmount = 0;
            }
            bean.LeadId = leadList.SelectedValue;
            bean.EducateMemo = txtTrainText.Text;
            bean.EducateFlg = 0;
            bean.LeadFlg = 0;
            bean.CommitFlg = 0;
            bean.AuditingFlg = 0;
            bean.CancelFlg = 0;
            bean.UserId = userId;
            int rowId = dao.InsertPersonTrain(bean);
            this.ViewState["ROW_ID"] = Convert.ToString(rowId);
        }
       
        //提示成功
        Response.Write("<script language=JavaScript>" +
                 "alert('" + HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "I0037").ToString().Replace("{0}", "保存") + "');</script>");

    }

    /*名称： btnSubmit_Click
     *功能： 提交培训申请
     *参数： 
     *返回： 无
     *说明： 无
     */
    protected void btnSubmit_Click(object sender, EventArgs e)
    {


        SysUserManager manager = new SysUserManager(Context);
        string userId = manager.getSysUserBean().getMstSysUserBean().SysUserId;
        PersonTrainBean bean = new PersonTrainBean();
        PersonTrainDao dao = new PersonTrainDao();
        ComValidateChecker validator = new ComValidateChecker();

        

        //编辑时候
        if (!string.IsNullOrEmpty(Convert.ToString(this.ViewState["ROW_ID"])))
        {
            PersonTrainBean dataBean = new PersonTrainBean();
            PersonTrainDao dataDao = new PersonTrainDao();
            dataBean.RowId = Convert.ToInt32(this.ViewState["ROW_ID"]);
            dataBean = dataDao.GetPersonTrain(dataBean);

            if (dataBean.EducateFlg == 0 && dataBean.LeadFlg == 0 && dataBean.CommitFlg == 0)
            {

                //数据验证
                validator.Add(new CheckRequired(txtTrainName.Text, new ComMessage("E0082", new string[] { "培训项目" })));
                validator.Add(new CheckRequired(txtTime.Text, new ComMessage("E0082", new string[] { "申请日期" })));
                validator.Add(new CheckDate(txtTime.Text, new ComMessage("E0037", "申请日期")));
                validator.Add(new CheckRequired(txtBeginDate.Text, new ComMessage("E0082", new string[] { "开始日期" })));
                validator.Add(new CheckDate(txtBeginDate.Text, new ComMessage("E0037", "开始日期")));
                validator.Add(new CheckDateRange(DateUtils.convertToString(DateTime.Now.Date), txtTime.Text, new ComMessage("E0330", new string[] { "申请日期", "当前日期" })));
                validator.Add(new CheckDateRange(txtTime.Text, txtBeginDate.Text, new ComMessage("E0330", new string[] { "开始日期", "申请日期" })));
                validator.Add(new CheckRequired(txtEndDate.Text, new ComMessage("E0082", new string[] { "结束日期" })));
                validator.Add(new CheckDate(txtEndDate.Text, new ComMessage("E0037", "结束日期")));
                validator.Add(new CheckDateRange(txtBeginDate.Text, txtEndDate.Text, new ComMessage("E0330", new string[] { "结束日期", "开始日期" })));
                validator.Add(new CheckDouble(txtAmount.Text, 9, 2, new ComMessage("E0036", new string[] { "培训预算" })));

                //校验不通过
                if (!validator.DoValidator())
                {
                    ((Design_MasterPage)this.Master).InfoMessage = validator.ErrorMessage;
                    return;
                }

                bean.RowId = Convert.ToInt32(this.ViewState["ROW_ID"]);
                bean.EducateName = txtTrainName.Text;
                bean.EmployeeId = Convert.ToString(this.ViewState["EMPLOYEE_ID"]);
                bean.EducateDate =  Convert.ToDateTime(txtTime.Text);
                bean.BeginDate  = Convert.ToDateTime(txtBeginDate.Text);
                bean.EndDate =  Convert.ToDateTime(txtEndDate.Text);
                if (!string.IsNullOrEmpty(txtAmount.Text))
                {
                    bean.EducateAmount = Convert.ToDecimal(txtAmount.Text);
                }
                else
                {
                    bean.EducateAmount = 0;
                }
                bean.LeadId = leadList.SelectedValue;
                bean.EducateMemo = txtTrainText.Text;
                //bean.CommitMemo = txtCommitText.Text;
                bean.EducateFlg = 1;
                bean.LeadFlg = 0;
                bean.CommitFlg = 0;
                bean.AuditingFlg = 0;
                bean.CancelFlg = 0;
                bean.UserId = userId;
                dao.UpdPersonTrain(bean);

                bean.RowId = Convert.ToInt32(this.ViewState["ROW_ID"]);
                bean = dao.GetPersonTrain(bean);
                string employeeName = (dao.GetEmployeeName(bean)).EmployeeName;

                //发送信息
                SendMessage(employeeName + "的培训申请已经确认,烦请领导审批！", this.leadList.SelectedValue);

            }
            else if (dataBean.EducateFlg == 1 && dataBean.LeadFlg == 0 && dataBean.CommitFlg == 0)
            {
                bean.RowId = Convert.ToInt32(this.ViewState["ROW_ID"]);
                bean.EducateName = txtTrainName.Text;
                bean.EmployeeId = dataBean.EmployeeId;
                bean.EducateDate = dataBean.EducateDate;
                bean.BeginDate = dataBean.BeginDate;
                bean.EndDate = dataBean.EndDate;
                if (!string.IsNullOrEmpty(txtAmount.Text))
                {
                    bean.EducateAmount = Convert.ToDecimal(txtAmount.Text);
                }
                else
                {
                    bean.EducateAmount = 0;
                }
                bean.LeadId = leadList.SelectedValue;
                //bean.AuditingEmployeeId = auditingList.SelectedValue;
                bean.CommitEmployeeId = commitList.SelectedValue;
                bean.EducateMemo = txtTrainText.Text;
                bean.LeadMemo = txtLeadText.Text;
                bean.EducateFlg = 1;
                bean.LeadFlg = 1;
                bean.CommitFlg = 0;
                bean.AuditingFlg = 0;
                bean.CancelFlg = 0;
                bean.UserId = userId;
                dao.UpdPersonTrain(bean);

                bean.RowId = Convert.ToInt32(this.ViewState["ROW_ID"]);
                bean = dao.GetPersonTrain(bean);
                string employeeName = (dao.GetEmployeeName(bean)).EmployeeName;

                //发送信息
                SendMessage(employeeName + "的培训申请已经确认,烦请领导审批！", this.commitList.SelectedValue);
            }

            else if (dataBean.EducateFlg == 1 && dataBean.LeadFlg == 1 && dataBean.CommitFlg == 0)
            {
                bean.RowId = Convert.ToInt32(this.ViewState["ROW_ID"]);
                bean.EducateName = txtTrainName.Text;
                bean.EmployeeId = dataBean.EmployeeId;
                bean.EducateDate = dataBean.EducateDate;
                bean.BeginDate = dataBean.BeginDate;
                bean.EndDate = dataBean.EndDate;
                if (!string.IsNullOrEmpty(txtAmount.Text))
                {
                    bean.EducateAmount = Convert.ToDecimal(txtAmount.Text);
                }
                else
                {
                    bean.EducateAmount = 0;
                }
                bean.LeadId = leadList.SelectedValue;
                bean.CommitEmployeeId = commitList.SelectedValue;
                bean.AuditingEmployeeId = auditingList.SelectedValue;
                bean.EducateMemo = txtTrainText.Text;
                bean.LeadMemo = txtLeadText.Text;
                bean.CommitMemo = txtCommitText.Text;
                bean.EducateFlg = 1;
                bean.LeadFlg = 1;
                bean.CommitFlg = 1;
                bean.AuditingFlg = 0;
                bean.CancelFlg = 0;
                bean.UserId = userId;
                dao.UpdPersonTrain(bean);


                bean.RowId = Convert.ToInt32(this.ViewState["ROW_ID"]);
                bean = dao.GetPersonTrain(bean);
                string employeeName = (dao.GetEmployeeName(bean)).EmployeeName;

                //发送信息
                SendMessage(employeeName + "的培训申请已经确认,烦请领导审批！", this.auditingList.SelectedValue);
            }
        }
            //新建时候
        else
        {
            //数据验证
            validator.Add(new CheckRequired(txtTrainName.Text, new ComMessage("E0082", new string[] { "培训项目" })));
            validator.Add(new CheckRequired(txtTime.Text, new ComMessage("E0082", new string[] { "申请日期" })));
            validator.Add(new CheckDate(txtTime.Text, new ComMessage("E0037", "申请日期")));
            validator.Add(new CheckRequired(txtBeginDate.Text, new ComMessage("E0082", new string[] { "开始日期" })));
            validator.Add(new CheckDate(txtBeginDate.Text, new ComMessage("E0037", "开始日期")));
            validator.Add(new CheckDateRange(DateUtils.convertToString(DateTime.Now.Date), txtTime.Text, new ComMessage("E0330", new string[] { "申请日期", "当前日期" })));
            validator.Add(new CheckDateRange(txtTime.Text, txtBeginDate.Text, new ComMessage("E0330", new string[] { "开始日期", "申请日期" })));
            validator.Add(new CheckRequired(txtEndDate.Text, new ComMessage("E0082", new string[] { "结束日期" })));
            validator.Add(new CheckDate(txtEndDate.Text, new ComMessage("E0037", "结束日期")));
            validator.Add(new CheckDateRange(txtBeginDate.Text, txtEndDate.Text, new ComMessage("E0330", new string[] { "结束日期", "开始日期" })));
            validator.Add(new CheckDouble(txtAmount.Text, 9, 2, new ComMessage("E0036", new string[] { "培训预算" })));

            //校验不通过
            if (!validator.DoValidator())
            {
                ((Design_MasterPage)this.Master).InfoMessage = validator.ErrorMessage;
                return;
            }
                bean.EducateName = txtTrainName.Text;
                bean.EmployeeId = Convert.ToString(this.ViewState["EMPLOYEE_ID"]);
                bean.EducateDate = Convert.ToDateTime(txtTime.Text);
                bean.BeginDate = Convert.ToDateTime(txtBeginDate.Text);
                bean.EndDate = Convert.ToDateTime(txtEndDate.Text);
                if (!string.IsNullOrEmpty(txtAmount.Text))
                {
                    bean.EducateAmount = Convert.ToDecimal(txtAmount.Text);
                }
                else
                {
                    bean.EducateAmount = 0;
                }
                bean.LeadId = leadList.SelectedValue;
                bean.EducateMemo = txtTrainText.Text;
                //bean.CommitMemo = txtCommitText.Text;
                bean.EducateFlg = 1;
                bean.LeadFlg = 0;
                bean.CommitFlg = 0;
                bean.AuditingFlg = 0;
                bean.CancelFlg = 0;
                bean.UserId = userId;
                int rowId = dao.InsertPersonTrain(bean);
                this.ViewState["ROW_ID"] = Convert.ToString(rowId);
                bean.EmployeeId = Convert.ToString(this.ViewState["EMPLOYEE_ID"]);
                string employeeName = (dao.GetEmployeeName(bean)).EmployeeName;

                //发送信息
                SendMessage(employeeName + "的培训申请已经确认,烦请领导审批！", this.leadList.SelectedValue);

            }
            //提示成功
            Response.Write("<script language=JavaScript>" +
                     "alert('" + HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "I0037").ToString().Replace("{0}", "提交") + "');</script>");
        }
    

    /*名称： btnAmount_Click
     *功能： 审批培训申请
     *参数： 
     *返回： 无
     *说明： 无
     */
    protected void btnAmount_Click(object sender, EventArgs e)
    {
        SysUserManager manager = new SysUserManager(Context);
        string userId = manager.getSysUserBean().getMstSysUserBean().SysUserId;
        PersonTrainBean bean = new PersonTrainBean();
        PersonTrainDao dao = new PersonTrainDao();

        //审批时候
        if (!string.IsNullOrEmpty(Convert.ToString(this.ViewState["ROW_ID"])))
        {
            PersonTrainBean dataBean = new PersonTrainBean();
            PersonTrainDao dataDao = new PersonTrainDao();
            dataBean.RowId = Convert.ToInt32(this.ViewState["ROW_ID"]);
            dataBean = dataDao.GetPersonTrain(dataBean);

            bean.RowId = Convert.ToInt32(this.ViewState["ROW_ID"]);
            bean.EducateName = dataBean.EducateName;
            bean.EmployeeId = dataBean.EmployeeId;
            bean.EducateDate = dataBean.EducateDate;
            bean.BeginDate = dataBean.BeginDate;
            bean.EndDate = dataBean.EndDate;
            if (!string.IsNullOrEmpty(txtAmount.Text))
            {
                bean.EducateAmount = Convert.ToDecimal(txtAmount.Text);
            }
            else
            {
                bean.EducateAmount = 0;
            }
            bean.LeadId = leadList.SelectedValue;
            bean.CommitEmployeeId = commitList.SelectedValue;
            bean.AuditingEmployeeId = auditingList.SelectedValue;
            bean.EducateMemo = txtTrainText.Text;
            bean.LeadMemo = txtLeadText.Text;
            bean.CommitMemo = txtCommitText.Text;
            bean.AuditingMemo = txtAuditingText.Text;
            bean.EducateFlg = 1;
            bean.LeadFlg = 1;
            bean.CommitFlg = 1;
            if (rdoOk.Checked == true)
            {
                bean.AuditingFlg = 1;
                bean.CancelFlg = 0;
            }
            if (rdoCancel.Checked == true)
            {
                bean.AuditingFlg = 0;
                bean.CancelFlg = 1;
            }
            bean.UserId = userId;
            dao.UpdPersonTrain(bean);
            bean.EmployeeId = Convert.ToString(this.ViewState["EMPLOYEE_ID"]);
            string employeeName = (dao.GetEmployeeName(bean)).EmployeeName;
            bean.RowId = Convert.ToInt32(this.ViewState["ROW_ID"]);
            bean = dao.GetPersonTrain(bean);
            if (bean.AuditingFlg == 1)
            {
                //发送信息
                SendMessage(employeeName + "的培训申请已经审批通过!", bean.CommitEmployeeId);
                //发送信息
                SendMessage(employeeName + "的培训申请已经审批通过!", bean.EmployeeId);
                //发送信息
                SendMessage(employeeName + "的培训申请已经审批通过!", bean.LeadId);
            }
            else
            {
                SendMessage(employeeName + "的培训申请已经撤消!", bean.CommitEmployeeId);
                SendMessage(employeeName + "的培训申请已经撤消!", bean.EmployeeId);
                SendMessage(employeeName + "的培训申请已经撤消!", bean.LeadId);
            }
            //提示成功
            Response.Write("<script language=JavaScript>" +
                     "alert('" + HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "I0037").ToString().Replace("{0}", "审批") + "');</script>");

            
        }
    }

    /*名称： btnBack_Click
     *功能： 返回
     *参数： 
     *返回： 无
     *说明： 无
     */
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Context.Items["PERSON_ID"] = this.ViewState["PERSON_ID"];
        Context.Items["EMPLOYEE_ID"] = this.ViewState["EMPLOYEE_ID"];
        Context.Items["CMB_JOB_ID"] = ViewState["CMB_JOB_ID"];
        Context.Items["CMB_GROUP_ID"] = ViewState["CMB_GROUP_ID"];
        Context.Items["CMB_STATUS_ID"] = ViewState["CMB_STATUS_ID"];
        Context.Items["ParamPageIndex"] = ViewState["ParamPageIndex"];
        Context.Items["URL"] = ViewState["URL"];
        Context.Items["EMPLOYEE_STATUS"] = ViewState["EMPLOYEE_STATUS"];
        string directUrl = Convert.ToString(this.ViewState["MAIN_URL"]);

        //返回
        ControllerUtils.Transfer(this.Context, directUrl, false);

    }

    /*名称： SendMessage
     *功能： 发送短信
     *参数： msg 短信内容, employeeId 短信内容地址
     *返回： 无
     *说明： 无
     */
    private void SendMessage(string msg, string employeeId)
    {
        SysUserManager manager = new SysUserManager(Context);
        SysUserBean sysUserBean = manager.getSysUserBean();
        MstSysUserBean mstSysUserBean =
            sysUserBean == null ? null : sysUserBean.getMstSysUserBean();
        MstEmployeeBean mstEmpBean =
            sysUserBean == null ? null : sysUserBean.getEmployeeBean();
        string loginId = mstSysUserBean == null ? "" : mstSysUserBean.SysUserId;
        string emplyId = mstSysUserBean == null ? "" : mstSysUserBean.EmployeeId;

        MessageBean beanMsg = new MessageBean();
        beanMsg.Subject = "培训申请确认" + DateUtils.convertToString(DateTime.Now);
        beanMsg.Message = DateUtils.convertToString(DateTime.Now) + msg;
        beanMsg.MessageType = 3;
        beanMsg.SendDate = DateTime.Now;
        beanMsg.ReplyFlag = false;
        beanMsg.ReaderHistoryFlag = false;
        beanMsg.ImportantFlag = false;
        beanMsg.EmployeeId = emplyId;
        beanMsg.UserId = loginId;
        CommonSendMessageUtils sendMsg = new CommonSendMessageUtils(beanMsg, employeeId);
        sendMsg.SendMessage();
    }

}
